home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / snpd9611.zip / HEXDUMP.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  2KB  |  83 lines

  1. .I 0 2
  2. /* +++Date last modified: 17-Feb-1996 */
  3.  
  4. .I 3 1
  5. **  Originally written By Paul Edwards
  6. .D 4 1
  7. .I 5 4
  8. **
  9. **  Modified for SNIPPETS by Bob Stout
  10. **
  11. **  Uses ERR_EXIT.C and FERROF.C, also in SNIPPETS
  12. .I 11 1
  13. #include "errors.h"
  14. .D 14 1
  15. .I 18 1
  16.       long start, count, length;
  17. .D 19 1
  18. .I 21 1
  19.             ErrExit("Usage: HEXDUMP file_name [start] [length]");
  20. .D 22 4
  21. .I 26 1
  22.             sscanf(argv[2], "%li", &start);
  23. .D 27 1
  24. .I 29 1
  25.             sscanf(argv[3], "%li", &count);
  26. .D 30 1
  27. .I 31 13
  28.  
  29.       fp = cant(argv[1], "rb");
  30.  
  31.       fseek(fp, 0L, SEEK_END);
  32.       length = ftell(fp);
  33.       if (start > length)
  34.       {
  35.             ErrExit("Can't find position %ld in a %ld byte file",
  36.                   start, length);
  37.       }
  38.       if (fseek(fp, start, SEEK_SET))
  39.             ErrExit("Unable to find position %ld", start);
  40.  
  41. .D 32 7
  42. .I 44 3
  43.       int c, pos1, pos2, posn = (int)(start % 16L);
  44.       long x = 0L;
  45.       char prtln[80];
  46. .D 45 3
  47. .I 50 1
  48.             if (0 == (posn % 16) || 0 == x)
  49. .D 51 1
  50. .I 53 12
  51.                   sprintf(prtln,"%0.6X:", start + x);
  52.                   prtln[7] = ' ';
  53.                   pos1 = 8 + (int)(3 * posn);
  54.                   if (posn > 3)
  55.                         ++pos1;
  56.                   if (posn > 7)
  57.                         ++pos1;
  58.                   if (posn > 11)
  59.                         ++pos1;
  60.                   pos2 = 60 + (int)(posn);
  61.             }
  62.             sprintf(prtln + pos1, "%0.2X ", c);
  63. .D 54 5
  64. .I 61 1
  65.             pos1 += 3;
  66. .D 62 1
  67. .I 64 1
  68.             if (posn % 4 == 3)
  69. .D 65 1
  70. .I 66 2
  71.             if (posn % 16 == 15)
  72.             {
  73. .D 67 1
  74. .I 68 6
  75.                   posn = 0;
  76.             }
  77.             else  ++posn;
  78.             ++x;
  79.       }
  80.       if (posn % 16)
  81. .D 69 3
  82. .D 75 14
  83.